<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 2.24</title>
</head>

<body>
<?php
	if(isset($_POST['n']))
	{
		$chu="";
		$n=intval($_POST['n']);
		$tam=$n;
		$tram=(int)($tam/100);
		$tam%=100;
		$chuc=(int)($tam/10);
		$tam%=10;
		$donvi=$tam;
		if($n<999)
		{
			if(strlen($n)==1)
				$chu=DocDonVi($donvi,false);
			elseif(strlen($n)==2)
				$chu=DocChuc($chuc)." ".DocDonVi($donvi,true);
				else
					$chu=DocTram($tram)." ".DocChuc($chuc)." ".DocDonVi($donvi,true);
		}
		else
			$chu="Nhập 1 số (0->999)";
	}
	function DocDonVi($a,$hangchuc)
	{
		$chuso;
		switch($a)
		{
			case 1:$chuso="một";break;
			case 2:$chuso="hai";break;
			case 3:$chuso="ba";break;
			case 4:$chuso="bốn";break;
			case 5:if($hangchuc==true)$chuso="lăm";
					else $chuso="năm"
					;break;			
			case 6:$chuso="sáu";break;
			case 7:$chuso="bảy";break;
			case 8:$chuso="tám";break;
			case 9:$chuso="chín";break;
			case 0:$chuso="không";break;						
		}
		return $chuso;
	}
	function DocChuc($a)
	{
		$chuso;
		switch($a)
		{
			case 1:$chuso="mười";break;
			case 2:$chuso="hai mươi";break;
			case 3:$chuso="ba mươi";break;
			case 4:$chuso="bốn mươi";break;
			case 5:$chuso="năm mươi"
					;break;			
			case 6:$chuso="sáu mươi";break;
			case 7:$chuso="bảy mươi";break;
			case 8:$chuso="tám mươi";break;
			case 9:$chuso="chín mươi";break;
			case 0:$chuso="lẻ";break;						
		}
		return $chuso;
	}
	function DocTram($a)
	{
		$chuso;
		switch($a)
		{
			case 1:$chuso="một trăm";break;
			case 2:$chuso="hai trăm";break;
			case 3:$chuso="ba trăm";break;
			case 4:$chuso="bốn trăm";break;
			case 5:$chuso="năm trăm"
					;break;			
			case 6:$chuso="sáu trăm";break;
			case 7:$chuso="bảy trăm";break;
			case 8:$chuso="tám trăm";break;
			case 9:$chuso="chín trăm";break;
			case 0:break;						
		}
		return $chuso;
	}
?>
<form id="form1" name="form1" method="post" action="Bai2_24.php">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr bgcolor="#3300CC" style="text-align: center; color: #FFF; font-size: 24px;">
      <td colspan="3" nowrap="nowrap">ĐỌC SỐ</td>
    </tr>
    <tr>
      <td width="35%" nowrap="nowrap" bgcolor="#66CCFF">Nhập số (0-&gt;999)</td>
      <td nowrap="nowrap" bgcolor="#66CCFF"><input name="n" type="text" id="n" value="<?php echo $_POST['n'];?>" maxlength="3" /></td>
      <td nowrap="nowrap" bgcolor="#66CCFF"><input style="background-color:#3FF" type="submit" name="submit" id="submit" value="Đọc số" /></td>
    </tr>
    <tr>
      <td bgcolor="#66CCFF">Bằng chữ      </td>
      <td colspan="2" bgcolor="#66CCFF"><input name="chu" type="text" disabled="disabled" id="chu" style="background-color:#FFC; color:#F00; font-weight:bold" value="<?php echo $chu;?>" size="50" /></td>
    </tr>
  </table>
</form>
</body>
</html>